package cn.pda.serialport;

import android.os.Handler;
import android.os.Message;

import java.io.IOException;

public class Barcode1DManager {
	public static int Port = 0;
	public static int Power = 2;
	public static int BaudRate = 9600;
	private static Handler mhandler;
	private static ScanThread scanThread;
	public static int Barcode1D = 1001;
	private static String CodedFormat = "";
	/**
	 * 
	 * @param handler
	 * @return  b
	 */
	public boolean Open(Handler handler) {
		mhandler = handler;
		try {
			scanThread = new ScanThread(mhandler, Port, BaudRate, Power,CodedFormat);
			scanThread.start();
		} catch (SecurityException e) {
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	/**
	 * 
	 * @return
	 */
	public void Scan(){
		if (scanThread != null) {
			scanThread.scan();
		}
	}
	/**
	 * 
	 * @return
	 */
	public  boolean Close(){
		if (scanThread != null) {
			scanThread.interrupt();
			scanThread.close(Power, Port);
			return true;
		}
		return false;
	}
	public void SetCodedFormat(String format) {
		CodedFormat = format;
	}
}
